class Logistic < ActiveRecord::Base
  has_many   :orders
  has_many   :logistic_fees
  before_save :convert_province_array

  attr_accessor :province_array,:fee



  EXPRESS = 1
  EMS = 2
  POST = 3

   TYPE_CODE_FOR_FORM = [
    [ "快递",   EXPRESS ],
    [ "EMS",   EMS ],
    [ "平邮",   POST ]
  ]


  TYPE_CODE_FOR_ALIPAY = [
    [ "EXPRESS",   EXPRESS ],
    [ "EMS",   EMS ],
    [ "POST",   POST ]
  ]

  def convert_province_array
    return if !province_array
    province_array.values.each do |i|
      LogisticFee.delete_all(["province_id = ?",i])
      LogisticFee.create(:province_id=>i,
        :logistic_id=>self.id,
        :fee=>fee) if i!="0"
    end
  end
end
